package com.diaohw.platform.common.obj.log;

import cn.hutool.core.date.LocalDateTimeUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * @author 刁海文
 * @Remark request 操作日志
 * @since 2023/6/11 17:31
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
public class RequestLog extends BaseLog {


    /**
     * 请求方法
     */
    private String method;

    /**
     * URI
     */
    private String uri;

    /**
     * 方法描述
     */
    private String description;

    /**
     * 请求参数
     */
    private String requestData;

    /**
     * 响应数据
     */
    private String responseData;
    /**
     * 请求时间;
     */
    private LocalDateTime requestTime;
    /**
     * 响应时间;
     */
    private LocalDateTime responseTime;

    /**
     * 消耗时间（毫秒）
     */
    private Double   elapsed;

    public void computeElapsed() {
        this.elapsed = LocalDateTimeUtil.between(requestTime, responseTime, ChronoUnit.NANOS) / 1000000.0;
    }

}
